package edu.hz.controller;

import edu.hz.model.dto.NewsCommentDto;
import edu.hz.model.entity.NewsEntity;
import edu.hz.service.NewsService;
import edu.hz.util.web.ApiResponse;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin(origins = "*")
@RestController
public class NewsController {

    @Resource
    NewsService newsService;

    @GetMapping("/news/list")
    public ApiResponse<List<NewsEntity>> allNews() {
        return ApiResponse.success(newsService.getAllNews());
    }

    @GetMapping("/news/news-content")
    public ApiResponse<NewsEntity> getById(@RequestParam("id") Integer id) {
        return ApiResponse.success(newsService.selectById(id));
    }

    @GetMapping("/news/news-comments")
    public ApiResponse<List<NewsCommentDto>> commentsOfNews(@RequestParam("id") Integer id) {
        return ApiResponse.success(newsService.getCommentsByNewsId(id));
    }


}
